package com.example.meterialproject.activitys.transition.demo6

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.navigation.Navigation
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.recyclerview.widget.RecyclerView
import com.example.meterialproject.R
import com.example.meterialproject.exts.createRecyclerView
import java.util.concurrent.TimeUnit

/**
 *
 * @ClassName: TransitionDemo6FromFragment
 * @Author: android 超级兵
 * @CreateDate: 4/28/22$ 1:40 PM$
 * TODO
 */
class TransitionDemo6FromFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        postponeEnterTransition(0, TimeUnit.MILLISECONDS)

        return inflater.inflate(R.layout.layout_recycler_view, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        view.findViewById<RecyclerView>(R.id.recycler_view)
            .createRecyclerView(requireContext()) { itemView, url, _ ->
                val extras = FragmentNavigatorExtras(itemView to url)

                Navigation.findNavController(itemView)
                    .navigate(R.id.transitionDemo6ToFragment,
                        bundleOf(TransitionDemo6ToFragment.TRANSITION_NAME to url),
                        null,
                        extras)
            }
    }
}